/**
 *
 * User: c3t
 * Date: 14-1-22
 * Time: 下午9:16
 *
 */
define(function (require, exports, module) {
    var $ = require('js/lib/jquery');
    require('js/lib/core/jquery.validate')($);
    require('js/lib/core/jquery.validate.zh_CN')($);
    (function ($) {
        var __validate = $.fn.validator;
        $.fn.cmsValidate = function (opts) {
            //分别覆盖默认的rules和fields属性
            var __rules = $.extend({
                rules: {
                    pwd: [/^\w{3,6}$/, "请输入3-6位数字、字母、下划线"]
                    //判断opts?是否为空
                }}, opts ? (opts.rules || {}) : {});

            var __fields = $.extend({
                fields: {
                    username: "用户帐号:required;username",
                    name:"栏目名称:required",
                    oldPwd: "原始密码:required,pwd",
                    password: "用户密码:required,pwd",
                    confirmPwd: "确认密码:required;match(password)",
                    email: "邮箱地址:required:email",
                    validateCode:"验证码:required",
                    title:"文章标题:required",
                    cname:"文章栏目:required",
                    content:"文章内容:required",
                    summary:"文章摘要:required"
                }}, opts ? (opts.fields || {}) : {});


            var __defaultopts = $.extend(opts, {
                //判断opts?是否为空
                theme: opts ? (opts.theme) : 'yellow_right',
                rules: __rules.rules,
                fields: __fields.fields
            });

            //继承了$.fn.validator的属性,用自己设置属性覆盖默认属性
            $.extend($.fn.validator.prototype, __defaultopts);
            //伪装的方式继承了$.fn.validator的方法
            __validate.call(this, __defaultopts);
            return this;
        }
    })($);

});
